#ifndef GLWIDGET_H
#define GLWIDGET_H

#include "src/scene.h"
#include "input.h"

#include <QGLWidget>
#include <QMouseEvent>
#include <QFile>

class GLWidget : public QGLWidget {
	Q_OBJECT

    public:
        GLWidget(QWidget* = 0);
        ~GLWidget();

        QSize minimumSizeHint() const;
        QSize sizeHint() const;
        void wheelEvent(QWheelEvent *);
        void mousePressEvent(QMouseEvent *);
        void mouseMoveEvent(QMouseEvent *);

        Scene *newScene();
        Scene *getScene();
        std::vector<Object *> loadScene(QFile *);
        Object *loadObject(QFile *);
        void saveScene(QFile *);
        void saveObject(QFile *);
        std::vector<Object *> loadIn(QFile *);
        std::vector<Object *> loadOut(QFile *);
        void saveIn(QFile *);
        void saveOut(QFile *);
        void saveWed(QFile *);
        void convexHull();
        void tetrahedralization();

        bool isShowingAxis();
        bool isShowingGrid();
        bool isShowingVertices();
        bool isShowingEdges();
        bool isShowingWireframe();
        bool isShowingOpaque();
        bool isShowingNormal();
//        bool isShowingStepByStep();

    public slots:
        void setXRotation(int);
        void setYRotation(int);
        void setZRotation(int);

        void changeShowAxis(bool);
        void changeShowGrid(bool);
        void changeShowVertices(bool);
        void changeShowEdges(bool);
        void changeShowWireframe(bool);
        void changeShowOpaque(bool);
        void changeShowNormal(bool);
//        void changeShowStepByStep(bool);

    private:
        void initializeGL(void);
        void paintGL(void);
        void resizeGL(int, int);

        void normalizeAngle(int *);

        double zoom;
        double xMov;
        double yMov;
        double zMov;
        int xRot;
        int yRot;
        int zRot;
        QPoint lastPos;

        GLfloat light0_pos[4];
        GLfloat light0_color[4];
        Scene *scene;

        bool showAxis;
        bool showGrid;
        bool showVertices;
        bool showEdges;
        bool showWireframe;
        bool showOpaque;
        bool showNormal;
//        bool showStepByStep;
};

#endif
